package main

import "fmt"

func main() {
	//指针做为参数
	//参数传递，值传递和引用传递

	a := 10
	fmt.Println("fun1()函数调用前,a的值:", a) //10
	fun1(a)
	fmt.Println("fun1()函数调用后,a的值:", a) //10

	fun2(&a)
	fmt.Println("fun2()函数调用后,a的值:", a) //200

	arr1 := [4]int{1, 2, 3, 4}
	fmt.Println("func3()函数调用前,arr1的值:", arr1) //[1 2 3 4]
	fun3(arr1)
	fmt.Println("func3()函数调用后,arr1的值:", arr1) //[1 2 3 4]

	fun4(&arr1)
	fmt.Println("func4()函数调用后,arr1的值:", arr1) //[200 2 3 4]
}

//int做参数，正常都是值传递 num = a = 10
func fun1(num int) {
	fmt.Println("函数fun1()中,num的值:", num) //10
	num = 100
	fmt.Println("函数fun1()中修改num:", num) //100
}

//int指针做参数，指针类型的都是引用传递，传递的是类型的地址
func fun2(p1 *int) {
	fmt.Println("函数fun2()中,p1的值:", *p1) //10
	*p1 = 200
	fmt.Println("函数fun2()中修改p1:", *p1) //200
}

//array做参数，就是正常的数组值传递
func fun3(arr2 [4]int) {
	fmt.Println("函数fun3()中,arr2数值是:", arr2) //[1 2 3 4]
	arr2[0] = 100
	fmt.Println("函数fun3()中,修改元素0后arr2数值是:", arr2) //[100 2 3 4]
}

//数组指针做参数，引用传递
func fun4(p2 *[4]int) {
	fmt.Println("函数fun4()中,p2数值是:", p2) //&[1 2 3 4]
	p2[0] = 200
	fmt.Println("函数fun4()中,修改元素0后p2数值是:", p2) //&[200 2 3 4]
}
